<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>学生管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-body">
    <div class="demoTable">
        <form class="layui-form layui-col-md12 x-so">
            <input id="sid" type="text" name="sid" placeholder="请输入学号" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加用户','./student-add.html',600,400,sync_data)">
            <i class="layui-icon"></i>添加
        </button>
    </xblock>

    <table id="student_table" class="layui-table">

    </table>
</div>
<script>

    function sync_data() {
        layui.use(['table', 'form'], function () {
            var $ = layui.jquery;
            var table = layui.table;


            table.render({
                elem: '#student_table'
                , method: "GET"
                , where: {m: 1}
                , url: "/api/student"
                , response: {statusCode: 1}
                , parseData: function (res) { //res 即为原始返回的数据

                    $.each(res.data, function (index, item) {
                        item["action"] = '<button class="layui-btn layui-btn-xs" onclick="x_admin_show(\'删除\',\'student-del.html?id=' + item["id"] + '\' ,300,200, sync_data)">删除</button>';
                    });
                    return {
                        "code": res.status, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
                , height: 480
                , page: true //开启分页
                , cols: [[ //表头
                    {field: 'id', title: '学号', fixed: 'left'}
                    , {field: 'name', title: '姓名',}
                    , {field: 'class', title: '班级',}
                    , {field: 'pid', title: '身份证号',}
                    , {field: 'action', title: '操作'}
                ]]
                , id: "stu_table"
            })
        })
    }

    sync_data();

    layui.use(['table', 'form'], function () {
        var form = layui.form;
        var table = layui.table;
        //响应按钮
        form.on('submit(search)', function (data) {

                table.reload('stu_table', {
                    url: "/api/student"
                    , elem: '#student_table'
                    , method: "GET"
                    , where: {m: 0, id: data.field['sid']}
                    , response: {statusCode: 1}
                    , parseData: function (res) { //res 即为原始返回的数据
                        $.each(res.data, function (index, item) {
                            item["action"] = '<button class="layui-btn layui-btn-xs" onclick="x_admin_show(\'删除\',\'student-del.html?id=' + item["id"] + '\' ,300,200, sync_data)">删除</button>';
                        });
                        return {
                            "code": res.status, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.data //解析数据列表
                        };
                    }

                })
                return false;
            }
        )
    })


</script>
</body>

</html>

